package com.lgw.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.lgw.bean.Bar;

public class BarDao {

	public ArrayList<Bar> query() {
		ArrayList<Bar> barArr = new ArrayList<Bar>();
		try {
			Class.forName("com.mysql.jdbc.Driver");
			Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test2?characterEncoding=utf8",
					"root", "123456");
			PreparedStatement stmt = conn.prepareStatement("SELECT * FROM pie");
			ResultSet rs = stmt.executeQuery();
			while (rs.next()) {
				Bar bar = new Bar();
				bar.setName(rs.getString("name"));
				bar.setNum(rs.getInt("num"));
				barArr.add(bar);
			}
			conn.close();
		} catch (SQLException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return barArr;
	}
}
